﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ObstacleRaceGame : GenericGame
{
	public static ObstacleRaceGame Game;

	public List<SpriteRenderer> m_PlayersRenderer;

	public KeyCode[] m_PlayersKeyCode;

	private KeyCode m_KeyTest;
	private Rect m_ButtonRect;
	private Vector3 m_RectPosition;

	public TextMesh m_ChosenInput;

	private void Awake()
	{
		InputManager.Instance.m_OnKeyPressed += OnKeyPressed;
		InputManager.Instance.m_OnButtonPressed += OnButtonPressed;
	}

	private void Update()
	{
		if(Input.GetKeyDown(m_PlayersKeyCode[0]))
		{
			m_PlayersRenderer[0].color = Color.blue;
		}
		else if(Input.GetKeyUp(m_PlayersKeyCode[0]))
		{
			m_PlayersRenderer[0].color = Color.white;
		}

		if(Input.GetKeyDown(m_PlayersKeyCode[1]))
		{
			m_PlayersRenderer[1].color = Color.red;
		}
		else if(Input.GetKeyUp(m_PlayersKeyCode[1]))
		{
			m_PlayersRenderer[1].color = Color.white;
		}

		if(Input.GetKeyDown(m_PlayersKeyCode[2]))
		{			
			m_PlayersRenderer[2].color = Color.yellow;
		}
		else if(Input.GetKeyUp(m_PlayersKeyCode[2]))
		{
			m_PlayersRenderer[2].color = Color.white;
		}

		if(Input.GetKeyDown(m_PlayersKeyCode[3]))
		{
			m_PlayersRenderer[3].color = Color.gray;			
		}
		else if(Input.GetKeyUp(m_PlayersKeyCode[3]))
		{
			m_PlayersRenderer[3].color = Color.white;
		}
	}

	private void OnKeyPressed(KeyCode i_KeyPressed)
	{
		/*
		Debug.Log(i_KeyPressed);
		int stop = 0;

		m_ChosenInput.text = i_KeyPressed.ToString();
		*/
	}
	
	private void OnButtonPressed(string[] i_ButtonPressed)
	{		
		/*
		m_ChosenInput.text = "";
		for(int i = 0; i < i_ButtonPressed.Length; i++)
		{
			if(i_ButtonPressed[i] != null)
			{
				if(i != 0)
				{
					m_ChosenInput.text += "\n";
				}
				m_ChosenInput.text += i_ButtonPressed[i];
			}
		}
		*/
	}

	private void OnDestroy()
	{
		if(InputManager.Instance != null) 
		{
			InputManager.Instance.m_OnKeyPressed -= OnKeyPressed;
			InputManager.Instance.m_OnButtonPressed -= OnButtonPressed;
		}
	}

	private void OnGUI()
	{
		/*
		m_ButtonRect.width = Screen.width * 0.25f;
		m_ButtonRect.height = Screen.height * 0.15f;
		
		m_RectPosition.x = Screen.width/2f;
		m_RectPosition.y = Screen.height - 50f;
		m_ButtonRect.position = m_RectPosition;
		
		m_KeyString = GUI.TextField(m_ButtonRect, m_KeyString, 25);
		*/
	}
}
